67
Explore Your Deductive Logic—Sudoku
67
STEP 22 Continued (Refreshcantbelist)
If sbox(k, j) = cantbelist(i, j, kk) Then foundincantbelist = 1
Next kk
If foundincantbelist = 0 Then
cantbelist(i, j, NextEmptyLocation(i, j)) = sbox(k, j)
End If
End If
‘ Next m
End If
Next k
‘* check all cells in the 3x3 box this cell belongs to
For k = 1 To 3
n = Int((i - 1) / 3) * 3 + k
For l = 1 To 3
p = Int((j - 1) / 3) * 3 + l
If (i = n And j = p) Then
m = m ‘do nothing
Else
If sbox(n, p) <> ““ Then
foundincantbelist = 0
For kk = 1 To 9
If sbox(n, p) = cantbelist(i, j, kk) Then foundincantbelist = 1
Next kk
If foundincantbelist = 0 Then
cantbelist(i, j, NextEmptyLocation(i, j)) = sbox(n, p)
End If
End If
End If
Next l
Next k
Next j
Next i
End Sub
3.9 CONCLUSION
Playing a Sudoku game is very entertaining. But to be able to solve it using your own
program is priceless. This chapter helps you to see the numerous patterns, which,
once coded into an algorithm, yield a surprising answer through the power of iter
ation. This macro makes solving Sudoku much faster than a human being can!
There is a rather simple strategy that one can apply to Sudoku games—fill in the
blanks with the nine possible digits (1–9) and check if all the rows, columns, and 3 by
3 squares have unrepeated digits. But this algorithm takes very long to yield a result.